<?php
namespace Shama;
/**
 * Inquiry Type Object.
 *
 * It represant a crm task, something that need to be
 * done on he inquiry. Such as recall a customer, update some informations.
 * A task always as an estimate duedate and a real due date.
 *
 *
 *
 * @author Xavier VILAIN
 * @package Shama
 * @license #license#
 *
 * @property string	$reference_class	Class of the reference object
 * @property string	$referenc_id		Id of the reference object
 * @property int	$taskid				Id of the Task
 * @property date	$estimate_duedate	Estimate Due Date
 * @property date	$duedate			Real Due Date (until the task has been proceed this date remain null)
 * @property string	$type				Task Type
 * @property bool	$auto				Automatic Task
 * @property string	$priority			Priority of the Task
 * @property string	$message_class		Class Message
 * @property string	$message_id			Message Id
 * @property string	$value1				Value1
 * @property string	$value2				Value2
 * @property string	$value3				Value3
 * @property string	$value4				Value4
 * @property text	$comment			Comment set by the user when working on the task
 * @property bool 	$loekz 				Deletion Flag if true is an been deleted
 * 
 * @method array references()
 */
class Task extends \Fox\Object\Versioned {

	/**
	 * Link to references
	 */
	const LINK_REFERENCES = 'references';
	
	/**
	 * Dunning type
	 */
	const TYPE_DUNNING = 'DU';

	/**
	 * Standard type
	 */
	const TYPE_STANDARD = 'ST';

	/**
	 * Standard type
	 */
	const STATUS_CLOSED = 'CL';
	
	/**
	 *
	 * Output Task Message in the current connection language
	 * @return string
	 */
	public function message()
	{
		return \Msg($this->message_class,
		$this->message_id,
		$this->value1,
		$this->value2,
		$this->value3,
		$this->value4);
	}

	/**
	 *
	 * Return
	 * @return TimeInterval
	 */
	public function delay()
	{
		$duedate = new \DateTime($this->estimate_duedate);
		$today = new \DateTime();
		$interval = $today->diff($duedate);
		return $interval->format('%R%a');
	}
}
\Fox\Dao::infos(Task::className(),new \Fox\Object\Info('tasks', \Fox\Databases::DB_APP)
);

// Link To References
\Fox\Object\Links::add(\Fox\Dao::link(Task\Reference::className(),Task\Reference::LINK_TASK)
	->to(Task::className(), Task::LINK_REFERENCES)
	->on('taskid')
	->versionFrom()
);
